package com.itcsystem.manager;

import com.itcsystem.connection.ConnectionUtility;
import java.util.ArrayList;
import java.util.List;
import java.sql.*;
import com.itcsystem.struct.Materia;

public class MateriaManager{
	private ConnectionUtility connectionUtility = ConnectionUtility.getConnectionUtility();

	public Integer insertMateria(Materia materia){
		String sql = "INSERTMATERIA ?,?,?";
	
		List<Object> parameters = new ArrayList<Object>();
		parameters.add(materia.getNombre());
		parameters.add(materia.getPlanestudios());
		connectionUtility.buildPreparedStatement(sql, parameters, true);
		
		return connectionUtility.executeSQLInsert();
	}
	public Boolean deleteMateria(int idMateria){
		String sql = "DELETEMATERIA ?";
		connectionUtility.buildPreparedStatement(sql, idMateria);
	
		return connectionUtility.executeSQLDelete();
	}
	public List<Materia> getMaterias(){
		List<Materia> listMateria = new ArrayList<Materia>();
		String sql = "SELECTMATERIA";
	
		try{
			ResultSet resultSet = connectionUtility.getResult(sql);
		
			if (resultSet !=null){
				while(resultSet.next()){
					Materia obj = new Materia();
		
					obj.setClave((int)resultSet.getObject("Clave"));
	
					obj.setNombre((java.lang.String)resultSet.getObject("Nombre"));
	
					obj.setPlanestudios((int)resultSet.getObject("Planestudios"));
					
					listMateria.add(obj);
				}
			}
		}
		catch(SQLException ex){
			ex.printStackTrace();
		}
	
		return listMateria;
	}
}
